package org.liveboardgames.agricola.control.delegates.action.processor
{
    import org.liveboardgames.agricola.control.events.intern.ActionEvent;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.card.Card;
    import org.liveboardgames.agricola.vo.common.Target;
    import org.liveboardgames.agricola.vo.player.Player;
    import org.liveboardgames.common.dictionary.collections.IMap;
    
    public class TakeAllActionProcessor extends ActionProcessor
    {
        public function TakeAllActionProcessor(action:Action)
        {
            super(action);
        }
        
        override public function execute():void
        {
            var target:Target = action.target;
            var link:Target = action.link;
            
            if (target is Player)
            {
                // Get the card from which to take the resources
                var card:Card = link as Card;
                var resourcesOnCard:IMap = card.resources;
                
                // Add the resources to the player
                var player:Player = target as Player;
                player.farm.addResources(resourcesOnCard);
                
                // Remove the resources from the card
                card.resetResources();
            }
            else
            {
                throw new Error("target not supported: " + target);
            }
            
            this.dispatchEvent(new ActionEvent(ActionEvent.ACTION_COMPLETE));
        }
    
    }
}